<template>
  <div class="app-container">
    <el-form ref="dataForm" :rules="rules" :model="temp" label-position="left" label-width="150px"
             style="width: 100%; padding: 0 30px;">

      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="定点供应商" prop="tmptAuthDeptId">
            <select-option
              v-model="temp.tmptAuthDeptId"
              :clearable=false
              prop-name="TmptAuthDeptId"
              :prop-ds-type=2
              prop-url="/citymh/coding/mhExcludeRound/select4column"
              filterable
            />
          </el-form-item>
          <el-form-item label="取消X轮中标资格" prop="forbidRound" >
            <el-input v-model.number="temp.forbidRound" placeholder="请输入数字" style="width: 200px; "/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
  import { createApi, updateApi, fetchList } from './api'
  // 导入多选项组件
  import SelectOption from '@/views/coding/components/SelectOption'

  export default {
    name: 'MhExcludeRound-FormDetail',

    components: { SelectOption },

    props: {
      isModule: {
        type: Boolean,
        default: false
      },
      row: {}
    },

    data() {
      return {
        rules: {
          tmptAuthDeptId: [{ required: true, message: 'required', trigger: 'blur' }],
          forbidRound: [{ required: true, message: 'required', trigger: 'blur' }, {
            type: 'number',
            message: '必须为数字值'
          }, {

            pattern: /^(1|[1-9]\d?|100)$/,

            message: '范围在0-100',

            trigger: 'blur'

          }]

        },
        temp: {}
      }
    },

    watch: {
      'row': {
        immediate: true, // vue首次赋值不触发watch的解决方法
        handler: function(nval) {
          if (this.isModule) {
            // this.temp = Object.assign({}, this.row) // copy obj
            if (this.isNull(nval)) {
              return
            }
            if (this.isNull(nval.id)) {
              return
            }
            this.getList(nval.id)
          }
        }
      }
    },

    methods: {
      getList(_id) {
        this.resetTemp()
        fetchList({ id: _id }).then(result => {
          if (!result.success) {
            this.notify(result)
            return
          }
          this.temp = result.map.rows[0]
        })
      },
      // 给外部调用，清空form
      resetTemp() {
        this.temp = {
          tmptAuthDeptId: '',
          forbidRound:'',
          id: undefined
        }
      },
      // 给外部调用，设置默认值，请根据实际情况修改id值
      defaultTemp() {
        this.temp = {
          deleteflag: 0 //设置默认值
        }
      },
      // 树表： 拿当前节点ID作为父节点ID，建立树关系
      setParentNodeId(id) {
        // this.temp.mhExcludeRoundId = id
        this.temp.parentId = id
      },
      // 给外部调用，插入记录
      createData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            const param = Object.assign({}, this.temp)
            createApi(param).then((r) => {
              this.notify(r)
              if (r.success) {
                this.resetTemp()
                // 从父组件调用此方法，进行回调下
                if (this.isModule) {
                  this.$emit('createResult')
                }
              }
            })
          }
        })
      },
      // 给外部调用，修改记录
      updateData() {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            // columnsTag.column4Add
            const param = { id: this.temp.id }
            param.tmptAuthDeptId = this.temp.tmptAuthDeptId
            param.forbidRound = this.temp.forbidRound

            updateApi(param).then((r) => {
              this.notify(r)
              if (r.success) {
                this.resetTemp()
                // 从父组件调用此方法，进行回调下
                if (this.isModule) {
                  this.$emit('updateResult')
                }
              }
            })
          }
        })
      },
      // 给外部调用，清除校验
      clearValidate() {
        this.$refs['dataForm'].clearValidate()
      }
    }

  }
</script>
<style>

</style>
